package com.nuit.cxl.mybatisdemo;

import com.nuit.cxl.mybatisdemo.config.SpringConfig;
import com.nuit.cxl.mybatisdemo.dao.AccountDao;
import com.nuit.cxl.mybatisdemo.domain.TblAccount;
import com.nuit.cxl.mybatisdemo.mybatis.GetSqlSession;
import com.nuit.cxl.mybatisdemo.service.AccountService;
import org.apache.ibatis.session.SqlSession;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

//@SpringBootApplication
public class MybatisdemoApplication {

    public static void main(String[] args) {

//        SpringApplication.run(MybatisdemoApplication.class, args);
//        SqlSession sqlSession = GetSqlSession.getAccountDao();
//        // 5. 执行SqlSession对象执行查询，获取结果User
//        AccountDao accountDao = sqlSession.getMapper(AccountDao.class);
//
//        TblAccount account = accountDao.findById(10);
//        System.out.println("accout-->" + account);
//
//        accountDao.save(new TblAccount("zhangshan",1.0));
//        sqlSession.commit();
//        System.out.println("end");

        ApplicationContext ctx = new AnnotationConfigApplicationContext(SpringConfig.class);
        AccountService accountService =ctx.getBean(AccountService.class);
        TblAccount account = accountService.findById(10);
        System.out.println("accout-->" + account);
        accountService.save(new TblAccount("lisi",1.0));
        System.out.println("end");

    }

}
